{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Properties of RG-58"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example demonstrates how to use skrf's to explore some properties of Coax (RG-58). This is done through the `media` package which provides basic transmission line models. Specifically, the coax is created using  by `DistributedCircuit`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "import skrf as rf\n",
    "from skrf.media import DistributedCircuit\n",
    "%matplotlib inline\n",
    "from pylab import * \n",
    "rf.stylely()\n",
    "\n",
    "\n",
    "\n",
    "# define a frequency object from a vector\n",
    "freq = rf.F.from_f(logspace(0,6,1001), unit='hz') \n",
    "\n",
    "# create a Media object for RG-58, based on distributed ckt values\n",
    "rg58 = DistributedCircuit(\n",
    "    frequency = freq,\n",
    "    C =93.5e-12,#F/m \n",
    "    L =273e-9,  #H/m\n",
    "    R =0,#53e-3,   #Ohm/m \n",
    "    G =0,       #S/m\n",
    "    )\n",
    "\n",
    "\n",
    "# loop thru values of resistivity and plot various quantities\n",
    "for k in (0,.1,1,10,100):    \n",
    "    rg58.R = k*1e-3\n",
    "    \n",
    "    figure(0)\n",
    "    ylabel('Phase Velocity (m/us)')\n",
    "    title('Phase Velocity')\n",
    "    loglog(freq.f_scaled, rg58.v_p*1e-6, label=r' %1.e $m \\Omega/m $'%k)\n",
    "    \n",
    "    figure(1)\n",
    "    ylabel('Real($Z_0$)')\n",
    "    title('Characteristic Impedance (Real)')\n",
    "    loglog(freq.f_scaled, rg58.z0.real, label=r'%1.e $m \\Omega/m $'%k)\n",
    "    \n",
    "    figure(2)\n",
    "    ylabel('-Imag($Z_0$)')\n",
    "    title('Characteristic Impedance (Imag)')\n",
    "    try:\n",
    "        plot(freq.f_scaled, -1*rg58.z0.imag, label=r'%1.e $m \\Omega/m $'%k)\n",
    "    except:\n",
    "        pass\n",
    "        \n",
    "    figure(3)\n",
    "    ylabel('Real($\\gamma$)')\n",
    "    title('Propagation Constant (Real)')   \n",
    "    try:\n",
    "        plot(freq.f_scaled, rg58.alpha, label=r'%1.e $m \\Omega/m $'%k)\n",
    "    except:\n",
    "        pass\n",
    "    \n",
    "    figure(4)\n",
    "    ylabel('Imag($\\gamma$)')\n",
    "    title('Propagation Constant (Imag)')\n",
    "    try:\n",
    "        plot(freq.f_scaled, rg58.beta, label=r'%1.e $m \\Omega/m $'%k)\n",
    "    except:\n",
    "        pass\n",
    "        \n",
    "    \n",
    "\n",
    "    \n",
    "from skrf.plotting import func_on_all_figs as foaf\n",
    "\n",
    "foaf(freq.labelXAxis)\n",
    "foaf(tight_layout)\n",
    "foaf(legend)\n",
    "foaf(loglog)\n",
    "\n",
    "tight_layout()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
